package com.baymax.test.scene.demo.maverick

import android.content.Intent
import com.airbnb.mvrx.MavericksState
import com.airbnb.mvrx.MavericksViewModel
import com.airbnb.mvrx.MavericksViewModelFactory
import com.airbnb.mvrx.ViewModelContext


class ResolveIntentViewModel(initialState: ResolveIntent) :
    MavericksViewModel<ResolveIntentViewModel.ResolveIntent>(initialState) {

    data class ResolveIntent(val intent: Intent) : MavericksState {
        val url by lazy { intent.getStringExtra("url") }
        val webUrl by lazy { intent.getStringExtra("webUrl") }
        val route by lazy { intent.getStringExtra("route") }
    }

    companion object : MavericksViewModelFactory<ResolveIntentViewModel, ResolveIntent> {
        override fun initialState(viewModelContext: ViewModelContext): ResolveIntent {
            return ResolveIntent(viewModelContext.activity.intent)
        }

        override fun create(
            viewModelContext: ViewModelContext,
            state: ResolveIntent
        ): ResolveIntentViewModel? {
            return super.create(viewModelContext, state)
        }
    }
}